package com.demo2do.fms.entity.reform;

import java.util.Date;

import javax.persistence.Column;
import javax.persistence.Entity;
import javax.persistence.FetchType;
import javax.persistence.GeneratedValue;
import javax.persistence.GenerationType;
import javax.persistence.Id;
import javax.persistence.ManyToOne;
import javax.persistence.SequenceGenerator;
import javax.persistence.Table;

import org.springframework.format.annotation.DateTimeFormat;

import com.demo2do.core.format.PersistentFormat;
import com.demo2do.fms.entity.supplier.common.Supplier;

/**
 * 供方约谈整改
 *
 * @author Ark
 *
 */
@Entity
@Table(name = "FMS_REFORM")
public class Reform {

    @Id
    @GeneratedValue(strategy = GenerationType.SEQUENCE, generator = "generator")
    @SequenceGenerator(name = "generator", sequenceName = "HIBERNATE_SEQUENCE", allocationSize = 1)
    private Long id;
    
    /** 约谈发起供方（非供方发起的，值为空） */
    @ManyToOne(fetch = FetchType.LAZY, optional = true)
    @PersistentFormat
    private Supplier originate;
    
    /** 被约谈供方 */
    @ManyToOne(fetch = FetchType.LAZY, optional = false)
    @PersistentFormat
    private Supplier recipient;
    
    /** 整改内容 */
    private String theme;
    
    /** 整改详情 */
    private String description;
    
    /** 出席人员*/
    private String attendee;
    
    /** 整改到期时间*/
    @DateTimeFormat(pattern = "yyyy-MM-dd")
    private Date endTime;
    
    /** 整改状态 */
    private ReformStatus reformStatus;
    
    /** 约谈时间 */
    @DateTimeFormat(pattern = "yyyy-MM-dd")
    private Date appointTime;
    
    /** 是否关闭 */
    @Column(name = "IS_CLOSED")
    private boolean closed;
    
    /** 关闭时间 */
    private Date closeTime;
    
    /** 附件一 */
    private String annexOne;
    
    /** 附件二 */
    private String annexTwo;
    
    /** 创建人 */
    private Long creator;

    /** 创建时间 */
    private Date createTime;

    /** 最近修改人 */
    private Long lastOperator;

    /** 最近修改时间 */
    private Date lastModifyTime;

    @Column(name = "IS_DISABLED")
    private Boolean disabled;
    
    /**
     * The default constructor
     */
    public Reform() {
    }
    
    /**
     * @param operator
     * @return
     */
    public Reform initialize(Long operator) {
        this.appointTime = new Date();
        this.closed = false;
        this.creator = operator;
        this.createTime = new Date();
        this.lastOperator = operator;
        this.lastModifyTime = new Date();
        this.disabled = false;
        this.reformStatus = ReformStatus.UNPROCESSED;
        return this;
    }
    
    /**
     * @param originate
     * @param operator
     * @return
     */
    public Reform initialize(Supplier originate, Long operator) {
        this.originate = originate;
        this.appointTime = new Date();
        this.closed = false;
        this.creator = operator;
        this.createTime = new Date();
        this.lastOperator = operator;
        this.lastModifyTime = new Date();
        this.disabled = false;
        this.reformStatus = ReformStatus.UNPROCESSED;
        return this;
    }
    
    /**
     * @param operator
     * @return
     */
    public Reform edit(Long operator) {
        this.lastOperator = operator;
        this.lastModifyTime = new Date();
        return this;
    }
    
    /**
     * @param operator
     * @return
     */
    public Reform close(Long operator) {
        this.closed = true;
        this.closeTime = new Date();
        this.lastOperator = operator;
        this.lastModifyTime = new Date();
        return this;
    }

    /**
     * @return the id
     */
    public Long getId() {
        return id;
    }

    /**
     * @return the originate
     */
    public Supplier getOriginate() {
        return originate;
    }

    /**
     * @return the recipient
     */
    public Supplier getRecipient() {
        return recipient;
    }

    /**
     * @return the theme
     */
    public String getTheme() {
        return theme;
    }

    /**
     * @return the description
     */
    public String getDescription() {
        return description;
    }

    /**
     * @return the attendee
     */
    public String getAttendee() {
        return attendee;
    }

    /**
     * @return the endTime
     */
    public Date getEndTime() {
        return endTime;
    }

    /**
     * @return the reformStatus
     */
    public ReformStatus getReformStatus() {
        return reformStatus;
    }

    /**
     * @return the appointTime
     */
    public Date getAppointTime() {
        return appointTime;
    }

    /**
     * @return the closed
     */
    public boolean isClosed() {
        return closed;
    }

    /**
     * @return the closeTime
     */
    public Date getCloseTime() {
        return closeTime;
    }

    /**
     * @return the annexOne
     */
    public String getAnnexOne() {
        return annexOne;
    }

    /**
     * @return the annexTwo
     */
    public String getAnnexTwo() {
        return annexTwo;
    }

    /**
     * @return the creator
     */
    public Long getCreator() {
        return creator;
    }

    /**
     * @return the createTime
     */
    public Date getCreateTime() {
        return createTime;
    }

    /**
     * @return the lastOperator
     */
    public Long getLastOperator() {
        return lastOperator;
    }

    /**
     * @return the lastModifyTime
     */
    public Date getLastModifyTime() {
        return lastModifyTime;
    }

    /**
     * @return the disabled
     */
    public Boolean getDisabled() {
        return disabled;
    }

    /**
     * @param id the id to set
     */
    public void setId(Long id) {
        this.id = id;
    }

    /**
     * @param originate the originate to set
     */
    public void setOriginate(Supplier originate) {
        this.originate = originate;
    }

    /**
     * @param recipient the recipient to set
     */
    public void setRecipient(Supplier recipient) {
        this.recipient = recipient;
    }

    /**
     * @param theme the theme to set
     */
    public void setTheme(String theme) {
        this.theme = theme;
    }

    /**
     * @param description the description to set
     */
    public void setDescription(String description) {
        this.description = description;
    }

    /**
     * @param attendee the attendee to set
     */
    public void setAttendee(String attendee) {
        this.attendee = attendee;
    }

    /**
     * @param endTime the endTime to set
     */
    public void setEndTime(Date endTime) {
        this.endTime = endTime;
    }

    /**
     * @param reformStatus the reformStatus to set
     */
    public void setReformStatus(ReformStatus reformStatus) {
        this.reformStatus = reformStatus;
    }

    /**
     * @param appointTime the appointTime to set
     */
    public void setAppointTime(Date appointTime) {
        this.appointTime = appointTime;
    }

    /**
     * @param closed the closed to set
     */
    public void setClosed(boolean closed) {
        this.closed = closed;
    }

    /**
     * @param closeTime the closeTime to set
     */
    public void setCloseTime(Date closeTime) {
        this.closeTime = closeTime;
    }

    /**
     * @param annexOne the annexOne to set
     */
    public void setAnnexOne(String annexOne) {
        this.annexOne = annexOne;
    }

    /**
     * @param annexTwo the annexTwo to set
     */
    public void setAnnexTwo(String annexTwo) {
        this.annexTwo = annexTwo;
    }

    /**
     * @param creator the creator to set
     */
    public void setCreator(Long creator) {
        this.creator = creator;
    }

    /**
     * @param createTime the createTime to set
     */
    public void setCreateTime(Date createTime) {
        this.createTime = createTime;
    }

    /**
     * @param lastOperator the lastOperator to set
     */
    public void setLastOperator(Long lastOperator) {
        this.lastOperator = lastOperator;
    }

    /**
     * @param lastModifyTime the lastModifyTime to set
     */
    public void setLastModifyTime(Date lastModifyTime) {
        this.lastModifyTime = lastModifyTime;
    }

    /**
     * @param disabled the disabled to set
     */
    public void setDisabled(Boolean disabled) {
        this.disabled = disabled;
    }

}
